# 基于官方Rust镜像构建
FROM rust:1.88-slim AS builder

# 安装musl工具链
RUN apt-get update && \
    apt-get install -y \
    musl-tools \
    libssl-dev && \
    export RUSTUP_DIST_SERVER="https://rsproxy.cn" && \
    export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" && \
    rustup install nightly &&\
    rustup default nightly &&\  
    rustup target add x86_64-unknown-linux-musl

WORKDIR /app

# 先复制依赖文件加速构建
COPY Cargo.toml .
COPY Cargo.lock .
COPY .cargo ./.cargo
RUN mkdir -p src \
    && echo 'fn main() {}' > src/main.rs \
    && cargo build --release  --target x86_64-unknown-linux-musl\
    && rm -rf src

# 复制源码并构建
COPY src ./src
# COPY log4rs.yaml .
RUN cargo build --release --target x86_64-unknown-linux-musl
